package com.EpidemicPrevention.controller;

import com.EpidemicPrevention.pojo.Volunteerinfo;
import com.EpidemicPrevention.service.VolunteerinfoServiceIpml;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/VolunteerinfoController")
public class VolunteerinfoController {

    @Autowired
    private VolunteerinfoServiceIpml volunteerinfoService;


    /*
     *添加用户
     * @Prama user 实体类
     * @return
     */
    @GetMapping("/addVolunteerinfo")
    @ResponseBody
    @CrossOrigin
    public JSON addVolunteerinfo(Volunteerinfo volunteerinfo) {
        return volunteerinfoService.addVolunteerinfo(volunteerinfo);
    }

    @GetMapping("/updataVolunteerinfo")
    @ResponseBody
    @CrossOrigin
    public  JSON updataVolunteerinfo(Volunteerinfo v_audit){
        return volunteerinfoService. updateVolunteerinfo (v_audit);
    }

    @GetMapping("/deleteVolunteerinfo")
    @ResponseBody
    @CrossOrigin
    public JSON deleteUser(int v_id) {
        return volunteerinfoService.deleteVolunteerinfo (v_id);
    }


    @GetMapping("/queryVolunteerinfo")
    @ResponseBody
    @CrossOrigin
    public JSON queryVolunteerinfo(@RequestParam("page") int page, @RequestParam("limit") int limit) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 1);
        json.put("msg", "");
        json.put("count", volunteerinfoService.queryVolunteerinfo (0, 100, null).size());
        json.put("data",volunteerinfoService.queryVolunteerinfo(page2, limit,null));
        System.out.println(json);
        return json;
    }



    @GetMapping("/selectVolunteerinfo")
    @ResponseBody
    @CrossOrigin
    public List<Volunteerinfo> selectVolunteerinfo (int v_id){
        return  volunteerinfoService.selectVolunteerinfo (v_id);
    }


    /**
     * 关键字查看情绪小妙招
     * @param page
     * @param limit
     * @param Keyword
     * @return
     */
    @GetMapping("/selectWhereVolunteerinfo")
    @ResponseBody
    @CrossOrigin
    public JSON selectWhereVolunteerinfo(@RequestParam("page")int page,@RequestParam("limit")int limit,@RequestParam("Keyword")String Keyword) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 1);
        json.put("msg", "查询成功");
        json.put("count", volunteerinfoService.queryVolunteerinfo(0, 100000,null ).size());
        json.put("data", volunteerinfoService.queryVolunteerinfo(page2, limit,Keyword));
        return json;
    }
}
